package com.hldsmart.smartda.fragment;


import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hldsmart.smartda.R;
import com.hldsmart.smartda.activity.home.FootprintActivity;
import com.hldsmart.smartda.activity.mine.AboutActivity;
import com.hldsmart.smartda.activity.mine.MyGroupActivity;
import com.hldsmart.smartda.activity.mine.MyQuanActivity;
import com.hldsmart.smartda.activity.mine.SettingActivity;
import com.hldsmart.smartda.activity.mine.SuggestActivity;
import com.hldsmart.smartda.commonutils.widget.CustomDialog;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 我的页面
 */
public class MineFragment extends Fragment implements View.OnClickListener {

    @Bind(R.id.iv_mine_setting)
    ImageView iv_mine_setting;
    @Bind(R.id.ll_mine_myquan)
    LinearLayout ll_mine_myquan;
    @Bind(R.id.ll_mine_mygroup)
    LinearLayout ll_mine_mygroup;

    @Bind(R.id.ll_myfootprint)
    LinearLayout ll_myfootprint;

    @Bind(R.id.ll_mine_kefu)
    LinearLayout ll_mine_kefu;
    @Bind(R.id.ll_mine_suggest)
    LinearLayout ll_mine_suggest;
    @Bind(R.id.ll_mine_about)
    LinearLayout ll_mine_about;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine, container, false);
        ButterKnife.bind(this, view);
        setListener();
        return view;
    }

    private void setListener() {
        iv_mine_setting.setOnClickListener(this);
        ll_mine_myquan.setOnClickListener(this);
        ll_mine_mygroup.setOnClickListener(this);

        ll_myfootprint.setOnClickListener(this);
        ll_mine_kefu.setOnClickListener(this);
        ll_mine_suggest.setOnClickListener(this);
        ll_mine_about.setOnClickListener(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_mine_setting:
                SettingActivity.startSettingActivity(getContext());
                break;
            case R.id.ll_mine_myquan:
                MyQuanActivity.startMyQuanActivity(getContext());
                break;
            case R.id.ll_mine_mygroup:
                MyGroupActivity.startMyGroupActivity(getContext());
                break;
            case R.id.ll_myfootprint:
                FootprintActivity.startFootprintActivity(getContext());
                break;
            case R.id.ll_mine_kefu:
                CustomDialog.Builder builder = new CustomDialog.Builder(getContext());
                builder.setTitle(R.string.prompt);
                builder.setMessage(R.string.kefu_phone);
                builder.setPositiveButton(R.string.call_phone, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Intent.ACTION_CALL);
                        Uri data = Uri.parse("tel:" + "15650701912");
                        intent.setData(data);
                        startActivity(intent);
                        dialog.dismiss();
                    }
                });
                builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.create().show();
                break;
            case R.id.ll_mine_suggest:
                SuggestActivity.startSuggestActivity(getContext());
                break;
            case R.id.ll_mine_about:
                AboutActivity.startAboutActivity(getContext());
                break;
        }
    }
}
